$(function(){
    let $btn = $("#btn");
    let $username = $("#username");
    let $password = $("#password");
    let $rpassword = $("#rpassword");
    let $nickname = $("#nickname");
    $btn.on("click",function(){
        var options = {
            url:"http://127.0.0.1:8888/users/register",
            type:"POST",
            data:{
                username:$username.val(),
                password:$password.val(),
                rpassword:$rpassword.val(),
                nickname:$nickname.val()
            },
            dataType:"json"
        }
        $.ajax(options)
        .done(function(data){
            if(data.code===1){
                alert("注册成功，马上跳转到登录页面")
                setTimeout(function(){
                    location.href = "./logIn.html"
                },2000);
            }else{
                alert(data.message);
            }
        })
    })
})

